package tag

import (
	"context"

	"gitee.com/zatto/project/tree/master/vblog/api/validator"
)

const AppName = "tags"

type Service interface {
	CreateTag(context.Context, *CreateTagRequest) (*Tag, error)
	QueryTag(context.Context, *QueryTagRequest) (*TagSet, error)
	RemoveTag(context.Context, *RemoveTagRequest) (*TagSet, error)
}

func NewCreateTagRequest(key, value string, blogId int) *CreateTagRequest {
	return &CreateTagRequest{
		Key:    key,
		Value:  value,
		BlogId: blogId,
	}
}

func NewDefaultCreateTagRequest() *CreateTagRequest {
	return &CreateTagRequest{}
}

type CreateTagRequest struct {
	Key    string `gorm:"column:t_key" json:"key" validate:"required"`
	Value  string `gorm:"column:t_value" json:"value" validate:"required"`
	BlogId int    `gorm:"cloumn:blog_id" json:"blog_id" validate:"required"`
}

func (req *CreateTagRequest) Validate() error {
	return validator.V().Struct(req)
}

func NewQueryTagRequest() *QueryTagRequest {
	return &QueryTagRequest{
		BlogIds: []int{},
	}
}

type QueryTagRequest struct {
	BlogIds []int
}

func (req *QueryTagRequest) Add(ids ...int) {
	req.BlogIds = append(req.BlogIds, ids...)
}

func NewRemoveTagRequest(id int) *RemoveTagRequest {
	return &RemoveTagRequest{
		BlogId: id,
	}
}

type RemoveTagRequest struct {
	BlogId int
}
